package com.nullpointer.idlegame.scene;

import com.nullpointer.idlegame.GlobalContent;
import com.nullpointer.idlegame.service.properties.CommonValue;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.scene.text.Text;

/**
 * 欢迎页
 */
public class WelcomePage implements CommonScene {

    private CommonValue commonValue = GlobalContent.getMainService().getCommonValue();

    private Scene instance = null;

    private Text showValue;

    @Override
    public Scene init() {
        Text text = new Text();
        text.setText("Hello!");
        text.setFont(new Font(40));
        Button btn = new Button("buttonChangeText");
        btn.setOnMousePressed((MouseEvent mouseEvent) -> {
            text.setText(mouseEvent.getButton().name());
        });
        Button btn2 = new Button("button");
        btn2.setOnMousePressed((MouseEvent mouseEvent) -> {
            text.setTranslateY(text.getTranslateY() + 10);
        });

        Button btn3 = new Button("修改 value 加量");
        btn3.setOnMousePressed((MouseEvent mouseEvent) -> {
            commonValue.setTestValueStep(commonValue.getTestValueStep() + 1);
        });

        Button btn4 = new Button("修改 value 减量");
        btn4.setOnMousePressed((MouseEvent mouseEvent) -> {
            commonValue.setTestValueStep(commonValue.getTestValueStep() - 1);
        });

        Button btn5 = new Button("修改 value 加速");
        btn5.setOnMousePressed((MouseEvent mouseEvent) -> {
            commonValue.setTestValueRangeMS(commonValue.getTestValueRangeMS() - 100);
        });

        Button btn6 = new Button("修改 value 减速");
        btn6.setOnMousePressed((MouseEvent mouseEvent) -> {
            commonValue.setTestValueRangeMS(commonValue.getTestValueRangeMS() + 100);
        });

        Button btn7 = new Button("to page");
        btn7.setOnMousePressed((MouseEvent mouseEvent) -> {
            ToPage page = new ToPage();
            GlobalContent.getBasicStage().setScene(page.init());
        });


        SimpleStringProperty testValue = GlobalContent.getMainService().getCommonValue().getTestValueShow();
        this.showValue = new Text();
        this.showValue.setFont(new Font(40));
        this.showValue.textProperty().bind(testValue);

        this.instance = new Scene(new VBox(btn, btn2, btn3, btn4, btn5, btn6, btn7, text, showValue), 1200, 800);

        return this.instance;
    }
}
